package com.yycx.module.bus.provider.service.hy.impl;

import com.yycx.module.bus.client.entity.BusInvoiceunit;
import com.yycx.module.bus.client.entity.hy.BusHyorderInovice;
import com.yycx.module.bus.provider.mapper.hy.BusHyorderInoviceMapper;
import com.yycx.module.bus.provider.service.BusInvoiceunitService;
import com.yycx.module.bus.provider.service.hy.BusHyorderInoviceService;
import com.yycx.common.mybatis.base.service.impl.BaseServiceImpl;
import com.yycx.common.mybatis.model.ResultBody;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.yycx.common.base.entity.EntityMap;
import com.yycx.common.mybatis.query.CriteriaQuery;
import org.springframework.transaction.annotation.Propagation;
import com.yycx.common.mybatis.query.CriteriaSave;
import org.springframework.transaction.annotation.Transactional;

/**
 * 结算发票接口实现类
 *
 * @author flyme
 * @date 2023-11-28
 */
@Service
@Transactional(rollbackFor = Exception.class)
public class BusHyorderInoviceServiceImpl extends BaseServiceImpl<BusHyorderInoviceMapper, BusHyorderInovice> implements BusHyorderInoviceService {

    @Autowired
    private BusInvoiceunitService invoiceunitService;

    @Override
    public ResultBody beforeAdd(CriteriaSave cs, BusHyorderInovice bhi, EntityMap extra) {
        return ResultBody.ok();
    }


    @Override
    @Transactional(propagation = Propagation.NOT_SUPPORTED, readOnly = true)
    public ResultBody beforePageList(CriteriaQuery<BusHyorderInovice> cq, BusHyorderInovice bhi, EntityMap requestMap) {
        cq.orderByDesc("bhi.createTime");
        return ResultBody.ok();
    }

    @Override
    public void afterGet(CriteriaQuery cq, EntityMap result) {
        Long invoiceUnitId = result.get("invoiceUnitId");
        BusInvoiceunit invoiceunit= invoiceunitService.getById(invoiceUnitId);
        result.put("contractDate",invoiceunit.getContractDate());
        super.afterGet(cq, result);
    }
}
